# -*-coding:utf-8 -*-

"""
# File       : testjob.py
# Time       ：2022/5/6 下午11:56
# Author     ：puppet
# version    ：python 3.8.1
# Description：
"""
from rentalsite.settings import ROOT_URLCONF
import socket

print(str(ROOT_URLCONF).split('.')[0])
# ROOT_URLCONF = 'rentalsite.urls'

# Get current ip.
CurrentServerIp = socket.gethostbyname(socket.gethostname())
print(CurrentServerIp)

DEBUG = True if CurrentServerIp in ('127.0.1.1', '127.0.0.1',) else False
print(DEBUG)

import pymysql

# 连接数据库
database = 'rentalsite'
mysqlUSER = 'debian-sys-maint'
mysqlPASSWORD = 'DlQDkcMiB9QaN9Vq'
mysqlPort = '3306'

conn = pymysql.connect(host='127.0.0.1',  # 连接名称，默认127.0.0.1
                       user='debian-sys-maint',  # 用户名
                       passwd='DlQDkcMiB9QaN9Vq',  # 密码
                       port=3306,  # 端口，默认为3306
                       db=database,  # 数据库名称 rentalsite
                       charset='utf8',  # 字符编码
                       )
# print(conn)
# cur = conn.cursor() # 生成游标对象
# sql="select * from `rent_article` " # SQL语句
# cur.execute(sql) # 执行SQL语句
# data = cur.fetchall() # 通过fetchall方法获得数据
# for i in data[:2]: # 打印输出前2条数据
#     print (i)
# cur.close() # 关闭游标
# conn.close() # 关闭连接

class Jianwei_SB():
    def __init__(self):
        self.host = '127.0.0.1'
        self.database = 'rentalsite'
        self.mysqlUSER = 'debian-sys-maint'
        self.mysqlPASSWORD = 'DlQDkcMiB9QaN9Vq'
        self.mysqlPort = 3306
        self.get_cursor()

    def get_cursor(self):
        self.conn = pymysql.connect(host=self.host,  # 连接名称，默认127.0.0.1
                               user=self.mysqlUSER,  # 用户名
                               passwd=self.mysqlPASSWORD,  # 密码
                               port=self.mysqlPort,  # 端口，默认为3306
                               db=self.database,  # 数据库名称 rentalsite
                               charset='utf8',  # 字符编码
                               )
        print(self.conn)
        return self.conn.cursor()

    def excute(self):
        sql="select * from `rent_article` "
        cur = self.get_cursor()
        cur.execute(sql)
        data = cur.fetchall()
        for i in data[:2]:
            print (i)
        cur.close() # 关闭游标
        conn.close() # 关闭连接


if __name__ == '__main__':
    jwsb = Jianwei_SB()
    jwsb.excute()




